﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 测试工具
{
    public partial class UserControl3 : UserControl
    {
        public UserControl3()
        {
            InitializeComponent();
        }

        private void UserControl3_SizeChanged(object sender, EventArgs e)
        {
            all_start_button.Location = new System.Drawing.Point(0, this.Size.Height - 68);
            button2.Location=new System.Drawing.Point(0, this.Size.Height - 136);
            test_ng_label.Location = new System.Drawing.Point(0, this.Size.Height - 176);
            test_num_label.Location = new System.Drawing.Point(0, this.Size.Height - 216);
        }

        private void UpdateSerials(object sender, EventArgs e)
        {

            for (int i = 0; i < (UserControl1.columns * UserControl1.row); i++)
            {
                bool change = true;
                string currentText = UserControl1.userControl12[i].comboBoxSerialBox.Text;
                UserControl1.userControl12[i].comboBoxSerialBox.Items.Clear(); //清空下拉框
                UserControl1.userControl12[i].comboBoxSerialBox.Items.Add("关闭");  //添加第一个选项
                string[] serial = SerialPort.GetPortNames(); //获取系统串口 
                foreach (string s in serial)    //将串口号添加到下拉框中
                {
                    UserControl1.userControl12[i].comboBoxSerialBox.Items.Add(s);
                    if (s.Equals(currentText)) change = false;
                }

                if (null == currentText || currentText.Equals("")|| change==true)
                {
                    UserControl1.userControl12[i].comboBoxSerialBox.SelectedIndex = 0;
                }
                else
                {
                    UserControl1.userControl12[i].comboBoxSerialBox.Text = currentText;
                }
            }
        }

        private void AllStart_button_Click(object sender, EventArgs e)
        {
            if (all_start_button.Text.Equals("全部开始"))
            {
                all_start_button.Text = "全部停止";
            }
            else
            {
                all_start_button.Text = "全部开始";
            }
            for (int i = 0; i < UserControl1.columns * UserControl1.row; i++)
            {
                UserControl1.userControl12[i].start_button_Click(null,null);
            }
        }
    }
}
